﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ShareTools
{
    public partial class schedule : Form
    {
        PLAYLIST pl1 = new PLAYLIST();
        public schedule()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Interval = 1000;
            this.label1.Text = Convert.ToString(DateTime .Now .ToLocalTime());

            listviewIni();
            ShowItemsOnList();

            dateTimePicker1.Format = DateTimePickerFormat.Custom ;
            dateTimePicker1.CustomFormat = "yyyy/MM/dd HH-mm-ss";
            dateTimePicker1.ShowUpDown = false ;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label1.Text = Convert.ToString(DateTime .Now .ToLocalTime ());
        }

        private void button2_Click(object sender, EventArgs e)
        {

            //foreach (string i in xstring)
            //{
            //    ListViewItem lv1 = new ListViewItem(); lv1.Checked = true; lv1.SubItems.Add(i); listView1.Items.Add(lv1);
            //}
        }
        /// <summary>
        /// listview初始化
        /// </summary>
        public void listviewIni()
        {
            listView1.View = View.Details;
            listView1.AllowColumnReorder = true;
            listView1.Sorting = SortOrder.None;
            listView1.CheckBoxes = true;
            listView1.Columns.Add("", 30, HorizontalAlignment.Center);
            listView1.Columns.Add("文件名", 150, HorizontalAlignment.Left);
            listView1.Columns.Add("长度", 150, HorizontalAlignment.Left);
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        public void ShowItemsOnList()
        {
            //获取content内容
            string exePath = System.Windows.Forms.Application.StartupPath;
            string filePath = exePath + "\\resource\\content.txt";
            REMOTEDIRECTORY rd1 = new REMOTEDIRECTORY();
            string[] fileStr = rd1.ReadRemoteFile(filePath);

            int count = 0;
            string[,] xstring = new string[10, 2];
            while (fileStr[count].Length > 10)
            {
                char[] sep = new char[] { ' ' };
                string[] tmpString = fileStr[count].Split(sep);
                foreach (string i in tmpString)
                {
                    //用来获得文件名
                    if (i.Length > 20)
                    {
                        int position = i.LastIndexOf("\\");
                        string x = i.Substring(position + 1);
                        xstring[count, 0] = x;
                    }
                    else if (i.Length == 8)
                    {
                        xstring[count, 1] = i;
                    }
                }
                count++;
            }
            for (int i = 0; i < 10; i++)
            {
                if (xstring[i, 0] != null)
                {
                    ListViewItem lv1 = new ListViewItem();

                    for (int j = 0; j < 2; j++)
                    {
                        lv1.SubItems.Add(xstring[i, j]);
                    }
                    listView1.Items.Add(lv1);
                }
            }
        }
        /// <summary>
        /// 获取当前选中的item的项，并加入到某一个字符串数组中去
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            
        }
        /// <summary>
        /// 用这个函数，取出播放的时间和文件名，用来写入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            ListView.CheckedListViewItemCollection checkItems = listView1.CheckedItems;
            foreach (ListViewItem i in checkItems)
            {
                for (int ii = 0; ii < 10; ii++)
                {
                    if (pl1.mediaInfo[ii, 0] == null)
                    {
                        pl1.mediaInfo[ii, 0] = i.SubItems[1].Text;
                        pl1.mediaInfo[ii, 1] = i.SubItems[2].Text;
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// 更新播放列表,需要将类中的数据都写入文档，按照固定的格式，这个应该是业务层代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
           // pl1.playStartTime = textBox1.Text
            MessageBox.Show(dateTimePicker1 .Text );
        }
    }
}
